# 使用Python 3.11作为基础镜像（3.13可能有兼容性问题）
FROM python:3.11-slim

# 设置工作目录
WORKDIR /app

# 安装系统依赖和编译工具
# 安装系统依赖
RUN apt-get update && apt-get install -y \
    gcc \
    g++ \
    libaio1 \
    wget \
    unzip \
    && rm -rf /var/lib/apt/lists/*

# 下载并安装Oracle Instant Client
RUN mkdir -p /opt/oracle \
    && cd /opt/oracle \
    && wget https://download.oracle.com/otn_software/linux/instantclient/1923000/instantclient-basic-linux.x64-19.23.0.0.0dbru.zip \
    && unzip instantclient-basic-linux.x64-19.23.0.0.0dbru.zip \
    && rm instantclient-basic-linux.x64-19.23.0.0.0dbru.zip \
    && echo /opt/oracle/instantclient_19_23 > /etc/ld.so.conf.d/oracle-instantclient.conf \
    && ldconfig

# 设置Oracle环境变量
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient_19_23:$LD_LIBRARY_PATH
ENV ORACLE_HOME=/opt/oracle/instantclient_19_23


# 先安装PyTorch CPU版本
RUN pip install torch==2.7.0 --index-url https://download.pytorch.org/whl/cpu

# 复制requirements.txt
COPY requirements.txt .

# 安装依赖
RUN pip install --no-cache-dir -r requirements.txt

# 复制项目文件
COPY main.py .
COPY config.py .
COPY models.py .
COPY cosmic_similarity_analyzer.py .

# 复制模型文件
COPY models/ ./models/
COPY static/ ./static/
COPY webfonts/ ./webfonts/

# 创建缓存目录
RUN mkdir -p cache

# 设置环境变量
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1

# 暴露端口
EXPOSE 8000

# 启动命令
CMD ["python", "main.py"]